from django.db import models
from tagstar.db.fields import TagsField

class State(models.Model):
    name = models.CharField(max_length=50, null=False)
    slug = models.SlugField(max_length=50, unique=True)
    abbreviation = models.CharField(max_length=3, null=False)
    tags = TagsField()

    class Meta:
        db_table = "location_state"
        ordering = ['name',]
        verbose_name_plural = 'States'

    def __unicode__(self):
        return self.name


class City(models.Model):
    name = models.CharField(max_length=50, null=False)
    slug = models.SlugField(max_length=50, unique=True)
    abbreviation = models.CharField(max_length=3, null=False)
    state = models.ForeignKey(State)
    tags = TagsField()

    class Meta:
        db_table = "location_city"
        ordering = ['state', 'name',]
        verbose_name_plural = 'Cities'

    def __unicode__(self):
        return self.name

class Suburb(models.Model):
    name = models.CharField(max_length=50, null=False)
    slug = models.SlugField(max_length=50, unique=True)
    postcode = models.IntegerField(max_length=4)
    city = models.ForeignKey(City)
    tags = TagsField()

    class Meta:
        db_table = "location_suburb"
        ordering = ['city','name']
        verbose_name_plural = 'Suburbs'

    def __unicode__(self):
        return self.name

class Street(models.Model):
    name = models.CharField(max_length=255, null=False)
    extension = models.CharField(max_length=50, null=False)
    slug = models.SlugField(max_length=255, unique=True)

    suburb = models.ForeignKey(Suburb)
    tags = TagsField()

    class Meta:
        db_table = "location_street"
        ordering = ['name', 'suburb']
        verbose_name_plural = 'Streets'

    def __unicode__(self):
        return self.name
